package client;

import java.io.*;
import java.net.*;

import vo.*;

public class ClientTest implements Runnable {
	
	Socket sock;
	InputStream in;
	OutputStream out;
	BufferedInputStream bis;
	BufferedOutputStream bos;
	ObjectInputStream ois;
	ObjectOutputStream oos;
	
	boolean flag;
	
	public ClientTest() throws UnknownHostException, IOException {
		sock = new Socket("203.240.202.13",7777);
		in = sock.getInputStream();
		out = sock.getOutputStream();
//		bis = new BufferedInputStream(in);
//		bos = new BufferedOutputStream(out);
//		ois = new ObjectInputStream(bis);
//		oos = new ObjectOutputStream(bos);
		ois = new ObjectInputStream(in);
		oos = new ObjectOutputStream(out);
		
		flag = true;
	}
	
	public void read(Object obj) {
		System.out.println("SERVER: " + obj.toString());
	}
	
	public void write(String str) throws IOException {
		MessageVO msg = new MessageVO(str);
		oos.writeObject(msg);
		oos.flush();
	}
	
	public void stop() {
		flag = false;
	}
	
	public void run() {
		while(flag) {
			try {
				read(ois.readObject());
			} catch (IOException e) {
				e.printStackTrace();
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			}
		}
	}
	
}
